#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
##############################################################################
#
#
#         ___           ___           ___           ___
#        /  /\         /  /\         /  /\         /  /\
#       /  /::\       /  /:/_       /  /:/_       /  /::\
#      /  /:/\:\     /  /:/ /\     /  /:/ /\     /  /:/\:\
#     /  /:/~/:/    /  /:/ /:/_   /  /:/ /::\   /  /:/~/:/
#    /__/:/ /:/___ /__/:/ /:/ /\ /__/:/ /:/\:\ /__/:/ /:/
#    \  \:\/:::::/ \  \:\/:/ /:/ \  \:\/:/~/:/ \  \:\/:/
#     \  \::/~~~~   \  \::/ /:/   \  \::/ /:/   \  \::/
#      \  \:\        \  \:\/:/     \__\/ /:/     \  \:\
#       \  \:\        \  \::/        /__/:/       \  \:\
#        \__\/         \__\/         \__\/         \__\/
#
#
#
#
#   This file is part of ReSP.
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
#   (c) Giovanni Beltrame, Luca Fossati
#       Giovanni.Beltrame@esa.int fossati@elet.polimi.it
#
##############################################################################


import Options

def build(bld):
    # Generation of the controller library
    obj = bld.new_task_gen('cxx', 'cshlib', 'pyembed')
    obj.source ='''
        simulation_engine.cpp controller.cpp callback.cpp sc_state_machine.cpp
    '''

    obj.target = 'sc_controller'
    obj.uselib = 'SYSTEMC_H BOOST BOOST_THREAD'
    obj.uselib_local = 'systemc utils'

    # Generation of the controller wrapper extension
    obj = bld.new_task_gen('pypp')
    obj.source ='''
        controller.hpp callback.hpp
    '''

    obj.target = 'sc_controller_wrapper'
    obj.uselib = 'SYSTEMC_H BOOST BOOST_PYTHON BOOST_THREAD'
    obj.uselib_local = 'systemc sc_controller'
    obj.start_decls = 'resp'
    obj.custom_code = """
# Exclude protected members
mb.calldefs( declarations.access_type_matcher_t( 'protected' ) ).exclude()

# Exclude simulation_engine
simulation_engine = mb.class_('simulation_engine')
simulation_engine.exclude()

# Exclude the state machine
controller_machine = mb.class_('ControllerMachine')
controller_machine.exclude()

# Exclude the callback variables
mb.variable('end_of_sim_callbacks').exclude()
mb.variable('pause_callbacks').exclude()
mb.variable('error_callbacks').exclude()

# Manage the controller class
controller = mb.class_('sc_controller')
controller.include()
controller.variable('error').include()
controller.variable('errorMessage').include()
controller.variable('timeTracker').exclude()
controller.variable('accumulatedTime').exclude()
controller.variable('interactive').include()
controller.member_functions(lambda decl: decl.name == 'getController').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object)
"""
